package com.ruoyi.project.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.system.domain.SysMobileUser;
import com.ruoyi.project.system.mapper.SysMobileUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.system.mapper.SysMomentCommentMapper;
import com.ruoyi.project.system.domain.SysMomentComment;
import com.ruoyi.project.system.service.ISysMomentCommentService;
import org.springframework.util.unit.DataUnit;

/**
 * 平台瞬间评论Service业务层处理
 *
 * @author jjp
 * @date 2020-04-14
 */
@Service
public class SysMomentCommentServiceImpl implements ISysMomentCommentService {
    @Autowired
    private SysMomentCommentMapper sysMomentCommentMapper;

    @Autowired
    private SysMobileUserMapper sysMobileUserMapper;

    /**
     * 查询平台瞬间评论
     *
     * @param commentId 平台瞬间评论ID
     * @return 平台瞬间评论
     */
    @Override
    public SysMomentComment selectSysMomentCommentById(Long commentId) {
        return sysMomentCommentMapper.selectSysMomentCommentById(commentId);
    }

    /**
     * 查询平台瞬间评论列表
     *
     * @param sysMomentComment 平台瞬间评论
     * @return 平台瞬间评论
     */
    @Override
    public List<SysMomentComment> selectSysMomentCommentList(SysMomentComment sysMomentComment) {
        return sysMomentCommentMapper.selectSysMomentCommentList(sysMomentComment);
    }


    /**
     * 查询平台瞬间评论列表
     *
     * @param momentId 平台瞬间评论
     * @return 平台瞬间评论
     */
    @Override
    public List<SysMomentComment> selectSysMomentId(Long momentId) {

        List<SysMomentComment> sysMomentComments = sysMomentCommentMapper.selectSysMomentId(momentId);
        for (int i = 0; i < sysMomentComments.size(); i++) {
            Long mobileUserId = sysMomentComments.get(i).getMobileUserId();
            SysMobileUser sysMobileUser = sysMobileUserMapper.selectSysMobileUserById(mobileUserId);
            String userName = sysMobileUser.getUserName();
            sysMomentComments.get(i).setUserName(userName);
        }
        return sysMomentComments;
    }


    /**
     * 新增平台瞬间评论
     *
     * @param sysMomentComment 平台瞬间评论
     * @return 结果
     */
    @Override
    public int insertSysMomentComment(SysMomentComment sysMomentComment) {
        sysMomentComment.setCreateDate(DateUtils.getNowDate());
        sysMomentComment.setStatus("0");
        return sysMomentCommentMapper.insertSysMomentComment(sysMomentComment);
    }

    /**
     * 修改平台瞬间评论
     *
     * @param sysMomentComment 平台瞬间评论
     * @return 结果
     */
    @Override
    public int updateSysMomentComment(SysMomentComment sysMomentComment) {
        return sysMomentCommentMapper.updateSysMomentComment(sysMomentComment);
    }

    /**
     * 批量删除平台瞬间评论
     *
     * @param commentIds 需要删除的平台瞬间评论ID
     * @return 结果
     */
    @Override
    public int deleteSysMomentCommentByIds(Long[] commentIds) {
        return sysMomentCommentMapper.deleteSysMomentCommentByIds(commentIds);
    }

    /**
     * 删除平台瞬间评论信息
     *
     * @param commentId 平台瞬间评论ID
     * @return 结果
     */
    @Override
    public int deleteSysMomentCommentById(Long commentId) {
        return sysMomentCommentMapper.deleteSysMomentCommentById(commentId);
    }

    @Override
    public Integer selectCount(SysMomentComment sysMomentComment) {
        return sysMomentCommentMapper.selectCount(sysMomentComment);
    }

    @Override
    public List<SysMomentComment> selectMomentCommentByParentCommentId(Long parentCommentId) {
        return sysMomentCommentMapper.selectMomentCommentByParentCommentId(parentCommentId);
    }
}
